package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.RemindUnitEnum;
import org.jsola.hr.dto.MemoConfigAddDTO;
import org.jsola.hr.dto.MemoConfigUpdateDTO;
import org.jsola.hr.entity.MemoConfigDO;
import org.jsola.hr.query.MemoConfigQuery;
import org.jsola.hr.service.IMemoConfigService;
import org.jsola.hr.vo.MemoConfigVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 备忘录配置
 *
 * @author zhr
 */
@Component
public class MemoConfigTestHelper extends BaseTestHelper {
    
    @Autowired
    private IMemoConfigService memoConfigService;

    /**
     * 生成add测试数据
     * @return MemoConfigAddDTO
     */
    public MemoConfigAddDTO getMemoConfigAddDTO(){
        MemoConfigAddDTO memoConfigAddDTO = new MemoConfigAddDTO();
        memoConfigAddDTO.setTitle(getRandomValue("varchar",255));
        memoConfigAddDTO.setContent(getRandomValue("varchar",2000));
        memoConfigAddDTO.setRemindNeed(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        memoConfigAddDTO.setRemindBefore(SafeKit.getInteger(getRandomValue("tinyint",4)));
        memoConfigAddDTO.setRemindType(SafeKit.getInteger(getRandomValue("tinyint",1)));
        memoConfigAddDTO.setRemindDate((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        memoConfigAddDTO.setRemindTime(getRandomValue("time",20));
        memoConfigAddDTO.setRemindUnit(RemindUnitEnum.DAY.getValue());
        memoConfigAddDTO.setRemindDayUnitValue(getRandomValue("varchar",20));
        memoConfigAddDTO.setRemindWeekUnitValue(getRandomValue("varchar",20));
        memoConfigAddDTO.setRemindMonthUnitValue(getRandomValue("varchar",20));
        memoConfigAddDTO.setRemindMonthUnitWeekUnit(getRandomValue("varchar",20));
        memoConfigAddDTO.setRemindMonthUnitWeekValue(getRandomValue("varchar",20));
        memoConfigAddDTO.setRemindYearUnitValue(getRandomValue("varchar",20));
        memoConfigAddDTO.setCompanyId(getRandomValue("varchar",32));
        return memoConfigAddDTO;
    }


    /**
     * 生成update测试数据
     * @return MemoConfigUpdateDTO
     */
    public MemoConfigUpdateDTO getMemoConfigUpdateDTO(MemoConfigVO memoConfigVO){
        return memoConfigService.selectDOById(memoConfigVO.getId(), SITE_ID).to(MemoConfigUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return MemoConfigQuery
     */
    public MemoConfigQuery getMemoConfigQuery() {
        MemoConfigQuery memoConfigQuery = new MemoConfigQuery();
        List<MemoConfigDO> memoConfigDOList = memoConfigService.list(new MemoConfigDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(memoConfigDOList)) {
            MemoConfigDO memoConfigDO = memoConfigDOList.get(0);
            memoConfigQuery = memoConfigDO.to(MemoConfigQuery.class);
        }
        return memoConfigQuery;
    }

    /**
     * 保存示例
     * @return MemoConfigVO
     */
    public MemoConfigVO saveMemoConfigExample(){
        MemoConfigAddDTO addDTO = this.getMemoConfigAddDTO();
        MemoConfigVO memoConfigVO = memoConfigService.save(addDTO,buildTokenUser());
        return memoConfigVO;
    }


}

